package com.wms.controller;

import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.entity.StockTakingTaskDetailList;
import com.wms.service.StockTakingTaskDetailListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wms.bean.PageBean;

@RestController
@RequestMapping("/stockTakingTask")
@Api(tags = "skh-盘点任务详情(列表)")
public class StockTakingTaskDetailListController {

    @Autowired
    private StockTakingTaskDetailListService stockTakingTaskDetailListService;

    /**
     * 查询盘点任务详情列表展示
     * @param code
     * @return
     */
    @GetMapping("/stockTakingTask/list")
    @ApiOperation("查询盘点任务详情(列表)")
    public ResultBean getTaskDetailList(@RequestParam String code) {
        StockTakingTaskDetailList stockTakingTaskDetailList = stockTakingTaskDetailListService.queryTaskDetailByList(code);
        if (stockTakingTaskDetailList != null) {
            return R.success("查询成功",stockTakingTaskDetailList);
        }
        return R.fail("查询失败");
    }
    
    /**
     * 统计该任务下的商品总数
     * @param code
     * @return
     */
    @GetMapping("/stockTakingTask/count")
    @ApiOperation("统计该任务下的商品总数")
    public ResultBean  getTaskDetailCount(@RequestParam String code) {
        try {
            int rs = stockTakingTaskDetailListService.countTaskDetail(code);
            // 只要查询成功就返回结果，不管数量是多少
            return R.success("查询成功", rs);
        } catch (Exception e) {
            return R.fail("查询失败: " + e.getMessage());
        }
    }
}
